package P009;

import org.junit.Test;

/**
 * @Author DJ同学
 * @Date 2021/2/8 23:49
 * @Version 1.0
 *  @Name 回文数
 *  @Problem https://leetcode-cn.com/problems/palindrome-number/
 *  思路：将数字对折 比较后半段是不是等于前半段
 */
public class Solution2 {

    @Test
    public void test01(){
        System.out.println(isPalindrome(21));
    }

    public boolean isPalindrome(int x) {

        boolean f=true;
        if(x<0||x>=10&&x%10==0) f=false;
        else{
            int num  = 0;
            int xx =x;
            while(num<xx){
                num*=10;
                num+=xx%10;
                xx/=10;
            }
            if(!(num==xx||num/10==xx||num*10==x)){
                f=false;
            }
        }
        return f;
    }
}
